package com.sjy;

import com.github.houbb.heaven.util.common.ArgUtil;
import com.sjy.bloomFilter.BloomFilter;
import com.sjy.type.Dict;
import com.sjy.type.SDS;
import org.junit.Test;

/**
 * @program: TotalTest
 * @description:
 * @author: 智慧的苏苏
 * @create: 2025-09-02 16:36
 **/
public class TotalTest {

    @Test
    public void SDSTest() {
        SDS s = new SDS("hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello");
        System.out.println(s);
        s.append(" world!");
        System.out.println(s);
        System.out.println("Substr(0,5): " + s.substring(0, 5));
        s.clear();
        System.out.println("After clear: " + s);
        s.free();
        ArgUtil.notNull(s,"s");
        System.out.println("After free: ");
    }

    @Test
    public void ProgressiveHashMapTest() {
        Dict m = new Dict();
        for (int i = 0; i < 20; i++) {
            m.set("k" + i, "v" + i);
            System.out.println(m.debugInfo());
        }
        // 访问期间也能推进 rehash
        System.out.println(m.get("k3"));
        // 主动推进 rehash（比如在空闲时调用）
        System.out.println("Final: " + m.debugInfo());
        // 删除测试
        System.out.println("del k5 = " + m.del("k5"));
        System.out.println("size = " + m.size());
    }

    @Test
    public void BloomFilterTest() {
        BloomFilter bf = new BloomFilter(1000, 0.01);
        System.out.println("bitSize=" + bf.getBitSize() + ", hashCount=" + bf.getHashCount());

        bf.add("apple").add("banana").add("pear");

        System.out.println("apple: " + bf.isExist("apple"));   // true
        System.out.println("banana: " + bf.isExist("banana")); // true
        System.out.println("peach: " + bf.isExist("peach"));   // false (大概率)
    }
}
